package com.pair.micro.common.bootstraptable;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/** bootstrap-table与服务器交互参数 http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/ */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BootstrapTable implements Serializable {

  /** 请求使用 * */
  /** 每页记录数 */
  private Integer limit;
  /** 页数 */
  private Integer offset;
  /** 默认显示的记录数 */
  private Integer pageNumber;
  /** 自带搜索框 */
  private String search;

  /** 响应使用 * */
  /** 返回结果 true成功 false失败 */
  private boolean success = true;
  /** 总记录数 */
  private Integer total;
  /** 当前条数 */
  private List<?> rows;
  /** 返回携带数据 */
  private Map<String, Object> paramMap;

  public BootstrapTable(List<?> rows) {
    this.total = rows.size();
    this.rows = rows;
  }

  public BootstrapTable(Integer total, List<?> rows) {
    this.total = total;
    this.rows = rows;
  }

  public BootstrapTable(Integer total, List<?> rows, Map<String, Object> paramMap) {
    this.total = total;
    this.rows = rows;
    this.paramMap = paramMap;
  }

  public static BootstrapTable btData(Integer total, List<?> rows) {
    return new BootstrapTable(total, rows);
  }

  public static BootstrapTable btData(Long total, List<?> rows) {
    return new BootstrapTable(total.intValue(), rows);
  }

  public static BootstrapTable noData() {
    return new BootstrapTable(0, Lists.newArrayList());
  }

  public static BootstrapTable allData(List<?> rows) {
    return new BootstrapTable(rows);
  }

  public static BootstrapTable extData(Integer total, List<?> rows, Map<String, Object> paramMap) {
    return new BootstrapTable(total, rows, paramMap);
  }
}
